﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Directory.Web
{
	public partial class User_UserInfo : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			Directory.Model.UserInfo user = UserDataProxy.GetUserInfo(Page.User.Identity.Name);
			ltName.Text = user.UserName;
			ltEmail.Text = user.Email;
			tbNickName.Text = user.NickName;
			tbRealName.Text = user.RealName;
			tbDescription.Text = user.Description;
			tbPIN.Text = user.PIN;
			tbQQ.Text = user.QQ;
			tbHandSet.Text = user.HandSet;
			tbPhone.Text = user.Phone;
			tbMSN.Text = user.MSN;
			tbAddress.Text = user.Address;
			tbPostCode.Text = user.PostCode;
			tbWebpage.Text = user.Webpage;
			ltCreateDate.Text = user.CreateDate.ToShortDateString();
		}
	}

		// 保存修改
		protected void btnSave_Click(object sender, EventArgs e)
		{
			Directory.Model.UserInfo user = UserDataProxy.GetUserInfo(Page.User.Identity.Name);
			user.NickName = tbNickName.Text;
			user.RealName = tbRealName.Text;
			user.Description = tbDescription.Text;
			user.PIN = tbPIN.Text;
			user.QQ = tbQQ.Text;
			user.HandSet = tbHandSet.Text;
			user.Phone = tbPhone.Text;
			user.MSN = tbMSN.Text;
			user.Address = tbAddress.Text;
			user.PostCode = tbPostCode.Text;
			user.Webpage = tbWebpage.Text;

			Directory.Model.UserInfo.ErrorCode errorCode;
			try
			{
				UserDataProxy.UpdateuserInfo(user, out errorCode);
			}
			catch
			{
				ltMsg.Text = "保存失败：服务器错误。";
				return;
			}
			switch (errorCode)
			{
				case Directory.Model.UserInfo.ErrorCode.Success:
					ltMsg.Text = "保存成功。";
					WebUtil.ClearUserCookie();
					break;
				case Directory.Model.UserInfo.ErrorCode.UserInfoIsNull:
					ltMsg.Text = "保存失败：无法获取用户信息。";
					break;
				default:
					ltMsg.Text = "保存失败：未知错误。";
					break;
			}
		}
	}
}